<template>
  <div class="mindWidth serviceProvider">
    <!-- <h4>服务商</h4> -->
    <div class="title flex items-middle space-between">
      <div class="lable">服务商</div>
      <a :href="`./serveDedils`" target="_blank" class="more">查看更多</a>
    </div>
    <el-carousel :interval="2000000" arrow="always" v-if="arr.length > 0">
      <el-carousel-item :autoplay="false" v-for="(item, index) in arr" :key="index">
        <ul>
          <li v-for="(v, i) in item" :key="i" class="changeHanld" @click="handleIndex(v.id)">
            <div class="image_area">
              <img :src="imgBaseUrl + v.companyLogo" />
            </div>
            <div class="content-text">
              <div class="merchant">{{ v.companyName }}</div>
              <div class="business">{{ v.synopsis }}</div>
            </div>
          </li>
        </ul>
      </el-carousel-item>
    </el-carousel>
  </div>
</template>

<script>
import { imgBaseUrl, getSerivice } from "../../api/api.js";

export default {
  name: "service",
  data() {
    return {
      getSeriviceList: [], // 接收服务商列表数据
      arr: [], // 接收服务商列表数据
      imgBaseUrl: "",
      total: 0,
      timer: null,
      form: {
        pageNo: 1,
        pageSize: 12
      }
    };
  },

  mounted() {
    this.imgBaseUrl = imgBaseUrl;
    this.getSerivice();
    // this.timer = setInterval(() => {
    //   this.getSerivice();
    // }, 3000);
  },
  methods: {
    // 跳转到详情页
    handleIndex(id) {
      let route = this.$router.resolve(`/dedils/${id}`);
      // let route = this.$router.resolve('/link/to/page'); // This also works.
      window.open(route.href, "_blank");
    },
    // 获取轮播图列表
    getSerivice() {
      getSerivice(this.form).then(res => {
        this.getSeriviceList = this.getSeriviceList.concat(res.result.records);
        this.total = res.result.total;
        this.getArr();

        // if (this.getSeriviceList.length >= this.total) {
        //   // console.log("关闭定时器");
        //   clearInterval(this.timer);
        // } else {
        //   this.refresh();
        // }
      });
    },
    // refresh() {
    //   this.form.pageNo++;
    //   this.getSerivice();
    // },
    getArr() {
      let list = this.getSeriviceList;
      for (let i = 0; i < Math.ceil(list.length / 4); i++) {
        let add = [];
        if ((i + 1) * 4 < list.length) {
          for (let j = 4 * i; j < (i + 1) * 4; j++) {
            add.push(list[j]);
          }
          this.arr.push(add);
        } else {
          for (let j = 4 * i; j < list.length; j++) {
            add.push(list[j]);
          }
          this.arr.push(add);
        }
      }
    }
  }
};
</script>

<style lang="less" scoped>
.serviceProvider {
  margin-top: 20px;
  margin-bottom: 70px;
  .title {
    padding: 20px 0;
    box-sizing: border-box;
    .lable {
      font-size: 18px;
      color: #333;
      font-weight: 700;
    }
    .more {
      font-size: 14px;
      color: #1678ff;
      cursor: pointer;
    }
  }
  // h4 {
  //   font-size: 20px;
  //   line-height: 60px;
  //   text-align: center;
  //   height: 60px;
  //   margin: 20px auto;
  // }
  ul {
    width: 1200px;
    margin-bottom: 20px;
    display: flex;
    .changeHanld {
      width: 250px;
      margin-right: 70px;
      background-color: #fff;
      font-size: 14px;
      transition: all 0.25s ease-out;
      position: relative;
      &:hover {
        transform: translateY(-10px);
        box-shadow: rgba(52 54 54, 0.2) -7px 3px 0px 4px;
      }
      &:last-child {
        margin-right: 0;
      }
      .image_area {
        width: 100%;
        margin: 0 auto;
        display: flex;
        align-items: center;
        padding: 20px 40px;
        box-sizing: border-box;
        img {
          display: flex;
          justify-content: center;
          align-items: center;
          margin: 0 auto;
          width: 100%;
          height: 100px;
        }
      }
      .content-text {
        width: 100%;
        padding: 10px;
        box-sizing: border-box;
        .merchant {
          margin: 10px 0;
          font-size: 14px;
          color: #333333;
          text-align: left;
          font-weight: 700;
        }
        .business {
          font-size: 14px;
          color: #75778b;
          text-align: left;
          height: 56px;
          display: -webkit-box;
          -webkit-box-orient: vertical;
          -webkit-line-clamp: 3; //限制行数
          overflow: hidden; //超出部分隐藏
          text-overflow: ellipsis;
        }
      }
    }
  }
}
/deep/ .el-carousel__arrow {
  background-color: rgba(31, 45, 61, 0.5);
}
</style>
